package com.magnificent.atlantis.client.robot.ui.panel;

import com.magnificent.atlantis.client.robot.RobotContext;
import com.magnificent.atlantis.client.robot.strategies.RobotStrategy;
import com.magnificent.atlantis.client.robot.strategies.RobotWorkerStrategy;
import com.magnificent.atlantis.client.robot.ui.configure.RobotConfiguration;
import com.magnificent.helpers.CommonUIHelper;
import org.jfree.chart.ChartPanel;

import javax.swing.*;
import java.awt.*;

/**
 * User: Babanin
 * Date: Sep 19, 2009
 * Time: 2:47:12 PM
 */
public class WorkerTabPanel extends AbstractUserTabPanel {
    public WorkerTabPanel(RobotConfiguration configuration) {
        super(configuration);

        initializeView();
    }

    private void initializeView() {
        setLayout(new BorderLayout());

        ChartPanel chartPanel = new ChartPanel(ganttChart);

        logTextPane.setBorder(BorderFactory.createLineBorder(Color.BLACK));

        JPanel shiftedChartPanel = CommonUIHelper.packInShiftedPanel(chartPanel, 5, 5, 5, 5);
        shiftedChartPanel.setBackground(Color.WHITE);

        JPanel chartPanelWithBorder = CommonUIHelper.packInPanel(shiftedChartPanel);
        chartPanelWithBorder.setBorder(BorderFactory.createLineBorder(Color.BLACK));

        splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
        splitPane.setLeftComponent(CommonUIHelper.packInShiftedPanel(chartPanelWithBorder, 5, 5, 5, 5));
        splitPane.setRightComponent(CommonUIHelper.packInShiftedPanel(new JScrollPane(logTextPane), 5, 5, 5, 5));

        add(splitPane, BorderLayout.CENTER);
    }

    protected RobotStrategy initializeRobotStrategy(RobotContext context) {
        System.out.println(context);
        return new RobotWorkerStrategy(context);
    }

    public void start() {
        robot.start();
        mailer.start();
        scheduler.start();

        System.out.println("START");
        System.out.println(mailer);
        System.out.println(scheduler);
        System.out.println(robot);
    }

    public void pause() {
    }

    public void stop() {
        robot.stop();
        mailer.stop();
        scheduler.stop();
    }
}
